-
Notifications
You must be signed in to change notification settings - Fork 0
Include refs for array schema paths #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances schema metadata extraction to include references for array schema paths by utilizing the caster.options.ref fallback. This ensures that array element references (e.g., arrays of ObjectIds referencing other models) are properly exposed in the schema paths metadata returned by document fetch operations.
Key Changes:
- Extended ref extraction to check
caster.options.refwhenoptions.refis not available - Applied the pattern consistently for both top-level and nested schema paths
- Updated three document fetching functions:
getDocument,getDocuments, andgetDocumentsStream
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/actions/Model/getDocumentsStream.js | Added caster-based ref fallback for both top-level schema paths and nested schema paths in the streaming document fetch |
| backend/actions/Model/getDocuments.js | Added caster-based ref fallback for both top-level schema paths and nested schema paths in the batch document fetch |
| backend/actions/Model/getDocument.js | Added caster-based ref fallback for top-level schema paths in the single document fetch |
Comments suppressed due to low confidence (2)
backend/actions/Model/getDocuments.js:96
- The schema path building logic (lines 74-96) is duplicated across three files: getDocuments.js, getDocumentsStream.js, and getDocument.js. Consider extracting this into a shared helper function to improve maintainability and ensure consistent behavior across all document fetch operations.
const schemaPaths = {};
for (const path of Object.keys(Model.schema.paths)) {
const schemaType = Model.schema.paths[path];
schemaPaths[path] = {
instance: schemaType.instance,
path,
ref: schemaType.options?.ref ?? schemaType.caster?.options?.ref,
required: schemaType.options?.required,
enum: schemaType.options?.enum
};
if (schemaType.schema) {
schemaPaths[path].schema = {};
for (const subpath of Object.keys(schemaType.schema.paths)) {
schemaPaths[path].schema[subpath] = {
instance: schemaType.schema.paths[subpath].instance,
path: subpath,
ref: schemaType.schema.paths[subpath].options?.ref ?? schemaType.schema.paths[subpath].caster?.options?.ref,
required: schemaType.schema.paths[subpath].options?.required,
enum: schemaType.schema.paths[subpath].options?.enum
};
}
}
}
backend/actions/Model/getDocumentsStream.js:86
- The schema path building logic (lines 64-86) is duplicated across three files: getDocuments.js, getDocumentsStream.js, and getDocument.js. Consider extracting this into a shared helper function to improve maintainability and ensure consistent behavior across all document fetch operations.
const schemaPaths = {};
for (const path of Object.keys(Model.schema.paths)) {
const schemaType = Model.schema.paths[path];
schemaPaths[path] = {
instance: schemaType.instance,
path,
ref: schemaType.options?.ref ?? schemaType.caster?.options?.ref,
required: schemaType.options?.required,
enum: schemaType.options?.enum
};
if (schemaType.schema) {
schemaPaths[path].schema = {};
for (const subpath of Object.keys(schemaType.schema.paths)) {
schemaPaths[path].schema[subpath] = {
instance: schemaType.schema.paths[subpath].instance,
path: subpath,
ref: schemaType.schema.paths[subpath].options?.ref ?? schemaType.schema.paths[subpath].caster?.options?.ref,
required: schemaType.schema.paths[subpath].options?.required,
enum: schemaType.schema.paths[subpath].options?.enum
};
}
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…com:mongoosejs/studio into codex/add-view-document-link-for-array-refs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Summary
Testing
Codex Task